package com.jala.base;

import com.jala.umf.common.model.UserVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2018/3/13.
 */
public class BaseAction {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     *
     */
    protected HttpSession getSession() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return request.getSession();
    }

    /**
     *
     */
    protected HttpServletRequest getRequest() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return request;
    }


    /**
     *
     */
    protected Integer getCurrentUserId() {
        UserVO u = this.getCurrentUser();

        if (u == null) {
            return null;
        }

        return u.getId();
    }

    /**
     *
     */
    protected String getCurrentUsername() {
        UserVO u = this.getCurrentUser();
        if (u == null) {
            return null;
        }
        return u.getUserName();
    }

    /**
     *
     */
    protected String getCurrentFullname() {
        UserVO u = this.getCurrentUser();
        if (u == null) {
            return null;
        }
        return u.getFullName();
    }

    /**
     *
     */
    protected UserVO getCurrentUser() {
        return Global.getUserInfo();
    }
}

